//
//  StopWatch.h
//  ChimooTimer
//
//	Provides the functionality of a stop watch
//  with count down and count up features
//  This is the MODEL of the project.  It shouldn't know anything
//  about the View or the Controller.
//
//  Delegate must respond to stopWatchDidStart:, stopWatchDidStop:, and stopWatchDidUpdate:.
//
//  Created by Ryan on Mon Sep 29 2003.
//  Chimoosoft (c) 2003-2007 Chimoosoft. All rights reserved.
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.


#import <Cocoa/Cocoa.h>

// Timer has two modes - count up, or count down.
typedef enum {
	UP		= 1001,
	DOWN	= 1002
} ModeType;


@interface StopWatch : NSObject {
	id delegate;
	
	NSTimer * timer;
	
	double lastUpdateNotificationMilliseconds;
	int lastIntSecond, lastIntMinute, lastIntHour;
	
	double startTimeInMilliseconds, stopTimeInMilliseconds;

	double displayUpdateMilliseconds;
	
	ModeType mode;		// countup or countdown mode?

	double countDownMilliseconds;		// how many milliseconds to countdown for?
	double userSelectedCountDownInMilliseconds;	// the users chooses this through menus.

	double lastTransparentTimeInMilliseconds;
	
	BOOL running;
}

// Returns time since last system boot in milliseconds.  Not affected by system clock changes.
+ (double)nowInMilliseconds;

//- (void)createThread:(id)param;


// delegate to receive stopwatch events
- (void)setDelegate:(id)aDelegate;

// modes
- (void)enterCountDownMode;
- (void)enterCountUpMode;
- (void)toggleCountDirection;

// control
- (void)start;
- (void)stop;
- (void)toggleStartStop;
- (void)reset;
- (void)resumeTransparentlyFromLastStop;

- (void)setUserCountDownMilliseconds:(double)milli;
- (void)setUserCountDownSeconds:(double)seconds;
- (double)userCountDownSeconds;
- (double)userCountDownMilliseconds;
- (double)countingDownUntilInSeconds;

- (void)setRefreshRate:(float)newRate;

- (BOOL)isRunning;
- (BOOL)isInCountDownMode;

- (double)elapsedTimeInSeconds;
- (NSNumber*)elapsedTimeInSecondsAsNumber;
- (double)elapsedTimeInMilliseconds;


- (double)totalSeconds;
- (void)hours:(out int *)h minutes:(out int *)m seconds:(out double*)s;


@end


// Delegate may implement these methods.

@interface NSObject (CMSStopWatchDelegate) 

- (void)stopWatchDidUpdate:(StopWatch*)theWatch;
- (void)stopWatchDidStart:(StopWatch*)theWatch;
- (void)stopWatchDidStop:(StopWatch*)theWatch;
- (void)stopWatchDidExpire:(StopWatch*)theWatch;
- (void)stopWatchDidReset:(StopWatch*)theWatch;
- (void)stopWatchDidTickSecond:(StopWatch*)theWatch;
- (void)stopWatchDidTickMinute:(StopWatch*)theWatch;
- (void)stopWatchDidTickHour:(StopWatch*)theWatch;

@end
